package com.cy.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;

/**
 * <p>Description: [后台角色]</p>
 * @author         [曹悦] 
 */
@Entity
@Table(name = "CY_BACK_ROLE")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
public class BackRole implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4068364694738218770L;
	
	private Long id;
	private String name;		//角色名
	private String remark;		//备注  
	
	private Set<BackRolePurView> rolePurviewSet = new HashSet<BackRolePurView>();
	private Set<BackUserRole> userRoleSet=new HashSet<BackUserRole>();
	
	@Id
	@Column(precision = 22, scale = 0)
	@SequenceGenerator(name = "CY_BACK_ROLE_SEQ", sequenceName = "CY_BACK_ROLE_SEQ",allocationSize=1,initialValue=1)
	@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "CY_BACK_ROLE_SEQ")
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	@Column(length=50,name="name",nullable=false)
	public void setName(String name) {
		this.name = name;
	}
	public String getRemark() {
		return remark;
	}
	@Column(length=255,name="remark")
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
	@BatchSize(size=50)
	public Set<BackRolePurView> getRolePurviewSet() {
		return rolePurviewSet;
	}
	public void setRolePurviewSet(Set<BackRolePurView> rolePurviewSet) {
		this.rolePurviewSet = rolePurviewSet;
	}
	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
	@BatchSize(size=50)
	public Set<BackUserRole> getUserRoleSet() {
		return userRoleSet;
	}
	public void setUserRoleSet(Set<BackUserRole> userRoleSet) {
		this.userRoleSet = userRoleSet;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final BackRole other = (BackRole) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}


	
	
	

}
